package com.buer.storage.controller;

import com.buer.storage.dto.AreaDto;
import com.buer.storage.dto.DepartmentDto;
import com.buer.storage.entity.Area;
import com.buer.storage.service.AreaService;
import com.buer.storage.vo.R;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/area")
public class AreaController {
    @Resource
    private AreaService areaService;

    //增加库区
    @PostMapping("/add.do")
    public R add(@RequestBody AreaDto areaDto) {
        if (areaService.add(areaDto) > 0) {
            return R.setR(1, "添加库区成功", null);
        }
        return R.setR(0, "添加库区失败", null);
    }

    //删除库区
    @GetMapping("/delete.do")
    public R delete(int areaId) {
        if (areaService.delete(areaId) > 0) {
            return R.setR(1, "删除库区成功", null);
        }
        return R.setR(0, "删除库区失败", null);
    }

    //修改库区
    @PostMapping("/update.do")
    public R update(@RequestBody Area area){
        if (areaService.update(area)>0){
            return R.setR(1,"修改库区成功",null);
        }
        return R.setR(0,"修改库区失败",null);
    }

    //根据id查询库区所有
    @GetMapping("/selectById.do")
    public Area selectById(int areaId){
        Area area = areaService.selectById(areaId);
        return area;
    }

    //根据库区id查询库位信息
    @GetMapping("/findDepartment.do")
    public List<DepartmentDto> findDepartment(int areaId){
        List<DepartmentDto> department = areaService.findDepartment(areaId);
        return department;
    }


}
